package com.iursp.validate.code;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.ServletWebRequest;

import com.iursp.domain.Const;


/**
 * 
 * @ClassName:  ValidateCodeController   
 * @Description:  
 * @author: ruiwu
 * @date:   2018年6月25日 下午7:30:59   
 *
 */
@RestController
public class ValidateCodeController {

    @Autowired
    private ValidateCodeProcessorHolder validateCodeProcessorHolder;

 /**
  * @Title: createCode   
  * @Description: 创建验证码，根据验证码类型不同，调用不同的 {@link ValidateCodeProcessor}接口实现 
  * 				图片验证码 : imageValidateCodeProcessor
  * 				短信验证码 : smsValidateCodeProcessor
  * @param: @param request
  * @param: @param response
  * @param: @param type
  * @param: @throws Exception      
  * @return: void      
  * @throws
  */
    @GetMapping(Const.DEFAULT_VALIDATE_CODE_URL_PREFIX + "/{type}")
    public void createCode(HttpServletRequest request, HttpServletResponse response, @PathVariable String type) throws Exception {
        validateCodeProcessorHolder.findValidateCodeProcessor(type).create(new ServletWebRequest(request, response));
    }
}